<template>
	<view class="content">
		<view class="tab">
			<view class="item" v-for="(item, index) in tabList" :key="index" @click="onTab(item)">
				<view :class="tabId == item.id ? 'title-on' : 'title'">{{ item.text }}</view>
			</view>
		</view>
		<view class="record-view f-col r-center" v-if="tabId!=4">
			<view class="item f-col r-center c-between" v-for="(item, index) in recordAry" :key="index"
				@click="onClickItem(item)">
				<text class="title">{{ item.checkTitle }}</text>
				<view class="view-line f-row c-between">
					<text>{{ item.createTime ? item.createTime : '' }} | 打卡</text>
					<text>参与{{ item.checkTotal ? item.checkTotal : 0 }}</text>
				</view>
				<view class="view-line f-row c-between">
					<text class="blue">{{ item.status == 0 ? '进行中' : '。；‘【' }}</text>
					<view class="f-row">
						<button open-type='share' class="btn">
							<u-icon name="zhuanfa" size="30"></u-icon>
						</button>
						<view @click.stop="onClickSet(item)">
							<u-icon name="more-dot-fill" size="30"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-else class="id_4">
			<view class="item" v-for="(item, index) in recordAry" :key="index">
				<view style="display: flex;flex-direction: row;">
					<view
						style="width: 100rpx;height: 100rpx;border-radius: 50%;overflow: hidden;border: 1rpx solid #000;margin-right: 50rpx;">
						<img :src="item.avatar" style="width: 100%;height: 100%;" alt="">
					</view>
					<view style="display:flex;flex-direction: column;justify-content: space-around;">
						<view>用&emsp;&emsp;户：{{item.name}}</view>
						<view>打卡时间：{{item.createTime}}</view>
					</view>
				</view>
				<view style="font-size: 34rpx;line-height: 60rpx;"> <text>打卡标题：</text> {{item.checkTitle}}
				</view>
				<view class="item_inner" v-for="(k,j) in item.list">
					<view v-if="k.type!='图片'">
						{{k.titleName}}：{{k.content}}
					</view>
					<view v-else style="padding: 20rpx 0;">
						{{k.titleName}}：<img :src="k.content" alt="" style="width: 120rpx;height: 120rpx;">
					</view>
				</view>
				<view>
					<button style="background-color: blue;color: #fff;float: right;border-radius: 30rpx;"
						@click="examineEvent(item.id)">审核</button>
				</view>
			</view>
		</view>
		<bottom-popup :showPopup="showPopup" :showTextAry="showPopupAry" @onClickItem="onClickPopup"
			@onClose="showPopup = false"></bottom-popup>
	</view>
</template>

<script>
	import bottomPopup from '@/myPage/components/bottomPopup.vue';
	import share from '@/mixins/share.js'
	export default {
		mixins: [share('分享打卡', "/myPage/sign/signOn")],
		data() {
			return {
				tabId: 1,
				tabList: [{
						id: 1,
						text: "我参与的"
					},
					{
						id: 2,
						text: "我创建的"
					},
					{
						id: 3,
						text: "我管理的"
					},
					{
						id: 4,
						text: "我审核的"
					}
				],
				recordAry: [],
				showPopup: false,
				showPopupAry: ["编辑", "删除"],
				selectId: 0
			};
		},
		components: {
			bottomPopup
		},
		onLoad() {
			this.tabId = 2;
			this.initData();
		},
		methods: {
			onTab(item) {
				this.tabId = item.id
				this.recordAry = [];
				this.initData();
			},
			onGetHtRecordList() {
				let that = this;
				this.$api.request({
					url: this.$api.getMeRecordList,
					data: {
						userId: this.$store.state.userId
					}
				}).then(resp => {
					if (resp.code == 200) {
						that.recordAry = resp.data;
					}
				});
			},
			onGetSolitaireList() {
				let that = this;
				this.$api.request({
					url: this.$api.solitaireList,
					data: {
						userId: this.$store.state.userId
					}
				}).then(resp => {
					if (resp.code == 200) {
						that.recordAry = resp.rows;
					}
				});
			},
			onGetManageSolitaireList() {
				let that = this;
				this.$api.request({
					url: this.$api.getCheckList,
					data: {
						userId: this.$store.state.userId
					}
				}).then(resp => {
					if (resp.code == 200) {
						that.recordAry = resp.rows;
					}
				});
			},
			onGetRecordList() {
				let that = this;
				this.$api.request({
					url: this.$api.htFormAuth,
					data: {
						userId: this.$store.state.userId,
						isAuth: 0
					}
				}).then(resp => {
					if (resp.code == 200) {
						that.recordAry = resp.data;
					}
				});
			},
			onClickItem(item) {
				uni.navigateTo({
					url: "/myPage/sign/signOnDetail?signid=" + item.id
				})
			},
			onClickSet(item) {
				this.showPopup = true;
				this.selectId = item.id;
			},
			onClickPopup(idx) {
				if (idx == 0) {
					uni.navigateTo({
						url: "/myPage/sign/signInCreate?signid=" + this.selectId
					})
				}
				if (idx == 1) {
					let that = this;
					this.$api.request({
						url: this.$api.htRecord + "/" + this.selectId,
						method: "DELETE"
					}).then(resp => {
						if (resp.code == 200) {
							that.initData();
						}
					});
				}
			},
			initData() {
				if (this.tabId == 1) {
					this.onGetHtRecordList();
				}
				if (this.tabId == 2) {
					this.onGetSolitaireList();
				}
				if (this.tabId == 3) {
					this.onGetManageSolitaireList();
				}
				if (this.tabId == 4) {
					this.onGetRecordList();
				}
			},
			examineEvent(id) {
				uni.showModal({
					title: '操作通知',
					content: '是否通过该审核',
					confirmText: '通过',
					success: (res) => {
						if (res.confirm) {
							this.$api.request({
								url: this.$api.examine,
								method: "POST",
								data: {
									id: Number(id)
								}
							}).then((res) => {
								console.log(res);
								if (res.code == 200) {
									uni.showToast({
										title: '审核通过'
									})
									this.onGetRecordList()
								}
							})
						}
					}
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	@import "@/static/css/app.scss";

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;

		.tab {
			width: 710rpx;
			display: flex;
			margin-top: 30rpx;

			.item {
				margin: 0 20rpx;
				font-size: 32rpx;
				// font-weight: bold;

				.title {
					color: #8A8A8A;
				}

				.title-on {
					color: #000;
					border-bottom: 5rpx solid #07C160;
				}
			}
		}

		.record-view {
			margin-top: 20rpx;
			width: 710rpx;

			.item {
				width: 100%;
				height: 160rpx;
				background: #fff;
				border-radius: 10rpx;
				margin-bottom: 20rpx;
				padding: 20rpx 0;

				.title {
					width: 670rpx;
					text-align: left;
					font-size: 28rpx;
					color: #000;
				}

				.view-line {
					width: 670rpx;
					color: #8A8A8A;
					font-size: 22rpx;

					.btn {
						display: flex;
						align-items: center;
						justify-content: center;
						border: none;
						background: none;
						margin-right: 30rpx;
					}

					.btn::after {
						border: none;
					}
				}

				.blue {
					color: #0ca6ff;
				}
			}
		}

		.id_4 {
			margin-top: 20rpx;
			width: 710rpx;
			display: flex;
			flex-direction: column;
			background: linear-gradient(to right, 45deg, #eeeeee, #d3d3d3);

			.item {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				border: 1rpx solid #bbb;
				border-radius: 30rpx;
				padding: 20rpx;
				margin-top: 20rpx;
				position: relative;

				.item_inner {
					display: flex;
					flex-direction: column;
				}

			}
		}
	}
</style>